home *** CD-ROM | disk | FTP | other *** search
/ All for Cell Phones: Sony Ericsson / Sony-Ericsson 2004.iso / Java / Chess / Fly_Chess.jar / SetupServlet.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-08-23  |  2.9 KB  |  82 lines

  1. import javax.microedition.lcdui.Command;
  2. import javax.microedition.lcdui.CommandListener;
  3. import javax.microedition.lcdui.Display;
  4. import javax.microedition.lcdui.Displayable;
  5. import javax.microedition.lcdui.Form;
  6. import javax.microedition.lcdui.TextField;
  7. import javax.microedition.rms.RecordStore;
  8.  
  9. public class SetupServlet implements CommandListener, ChessDisplayable {
  10.    private TextField servleturl = null;
  11.    private ChessLogic chesslogic = null;
  12.    private ChessDisplayable chessreturn = null;
  13.    private Form form;
  14.    private Command OKCommand;
  15.    private Command backCommand;
  16.  
  17.    public SetupServlet(ChessLogic var1, ChessDisplayable var2) {
  18.       this.chesslogic = var1;
  19.       this.chessreturn = var2;
  20.       this.initialize();
  21.    }
  22.  
  23.    public void commandAction(Command var1, Displayable var2) {
  24.       if (var1 == this.OKCommand) {
  25.          if (this.store()) {
  26.             MessageForm var3 = new MessageForm("Succes", "New URL stored", this.chessreturn);
  27.             var3.makeCurrent(CU.getDisplay());
  28.          } else {
  29.             MessageForm var4 = new MessageForm("Failure", "URL storage failed", this);
  30.             var4.makeCurrent(CU.getDisplay());
  31.          }
  32.       } else {
  33.          this.chessreturn.makeCurrent(CU.getDisplay());
  34.       }
  35.  
  36.    }
  37.  
  38.    private void initialize() {
  39.       this.form = new Form("Setup Servlet URL");
  40.       Object var1 = null;
  41.       this.OKCommand = new Command("Store", 4, 1);
  42.       this.backCommand = new Command("Back", 2, 1);
  43.       this.form.append("Provide: \n");
  44.  
  45.       try {
  46.          Object var2 = null;
  47.          RecordStore var5 = RecordStore.openRecordStore("Chess", false);
  48.          var4 = new String(var5.getRecord(1));
  49.          var5.closeRecordStore();
  50.       } catch (Exception var3) {
  51.          CU.shout("RS init: " + ((Throwable)var3).getMessage());
  52.          var4 = "";
  53.       }
  54.  
  55.       this.servleturl = new TextField("Servlet URL", var4, 150, 4);
  56.       this.form.append(this.servleturl);
  57.       this.form.addCommand(this.OKCommand);
  58.       this.form.addCommand(this.backCommand);
  59.       this.form.setCommandListener(this);
  60.    }
  61.  
  62.    public void makeCurrent(Display var1) {
  63.       var1.setCurrent(this.form);
  64.       this.form.setCommandListener(this);
  65.    }
  66.  
  67.    private boolean store() {
  68.       Object var1 = null;
  69.       String var2 = this.servleturl.getString();
  70.  
  71.       try {
  72.          RecordStore var5 = RecordStore.openRecordStore("Chess", false);
  73.          var5.setRecord(1, var2.getBytes(), 0, var2.length());
  74.          var5.closeRecordStore();
  75.          return true;
  76.       } catch (Exception var4) {
  77.          CU.shout("Store exception: " + ((Throwable)var4).getMessage());
  78.          return false;
  79.       }
  80.    }
  81. }
  82.